

import 'package:flutter/material.dart';

class Loading extends StatefulWidget {
  final Color? color;
  final double size;

  const Loading({Key? key, this.color, this.size = 20}) : super(key: key);

  @override
  State<Loading> createState() => _LoadingState();
}

class _LoadingState extends State<Loading> with SingleTickerProviderStateMixin {
  late AnimationController controller;
  int time = 1500;

  @override
  void initState() {
    super.initState();
    controller = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: time),
    )..repeat();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: AnimatedBuilder(
        animation: controller,
        builder: (a, b) {
          return loading(
            rotate: Tween<double>(
              begin: 0,
              end: 6,
            )
                .animate(
                  CurvedAnimation(
                    parent: controller,
                    curve: const Interval(
                      0,
                      1,
                    ),
                  ),
                )
                .value,
          );
        },
      ),
    );
  }

  Widget loading({required double rotate}) {
    return Transform.rotate(
        angle: rotate,
        child: Image.asset('assets/images/if-ui-laoding.png',
            color: widget.color, width: widget.size, height: widget.size));
  }
}
